package model

import "sync"

type MeetingList struct {
	meetings map[int]*Meeting
	lock     *sync.RWMutex
}

func NewMeetingList() *MeetingList {
	return &MeetingList{
		meetings: make(map[int]*Meeting),
		lock:     new(sync.RWMutex),
	}
}

// GetMeetings 获取所有会议
func (m *MeetingList) GetMeetings() map[int]*Meeting {
	m.lock.RLock()
	defer m.lock.RUnlock()

	return m.meetings
}

// AddMeeting 添加会议
func (m *MeetingList) AddMeeting(meeting *Meeting) {
	m.lock.Lock()
	defer m.lock.Unlock()

	m.meetings[meeting.id] = meeting
}

// GetMeetingById 根据会议号获取会议
func (m *MeetingList) GetMeetingById(id int) *Meeting {
	m.lock.RLock()
	defer m.lock.RUnlock()

	return m.meetings[id]
}

// DeleteMeeting 移除会议
func (m *MeetingList) DeleteMeeting(id int) {
	m.lock.Lock()
	defer m.lock.Unlock()

	delete(m.meetings, id)
}
